﻿using NPOI.SS.UserModel;
using NPOI.XSSF.UserModel;
using OfficeOpenXml;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Growatt.CreateCCode
{
    public class ClassTestExcel
    {

      public  static void testFile()
        {
            ExcelPackage.LicenseContext = LicenseContext.NonCommercial;
            string csvFilePath = Path.Combine(Environment.CurrentDirectory, @"EEClear.csv");
            string excelFilePath = Path.Combine(Environment.CurrentDirectory, @"工作簿8.xlsx");
            string excelFilePath2 = Path.Combine(Environment.CurrentDirectory, $"工作簿{System.DateTime.Now.ToString("ffff")}.xlsx");

            using (ExcelPackage package = new ExcelPackage(new FileInfo(excelFilePath)))
            {
                ExcelWorksheet worksheet = package.Workbook.Worksheets[0]; // 获取第一个工作表

                // 读取CSV文件数据
                string[] csvLines = File.ReadAllLines(csvFilePath);
                for (int i = 0; i < csvLines.Length; i++)
                {
                    string[] csvValues = csvLines[i].Split(',');
                    for (int j = 0; j < csvValues.Length; j++)
                    {
                        worksheet.Cells[i + 1, j + 1].Value = csvValues[j]; // 设置单元格值
                    }
                }

                package.Save(); // 保存Excel文件
            }

            Console.WriteLine("CSV数据已成功插入到Excel的第一个工作表中。");

        }
    }
}


